$(function() {
	/**
	 * 加载主页面歌手
	 */
	addMainSinger();

	$("img.lazy").lazyload({
		load : function() {
			$('#container').BlocksIt({
				numOfCol : 5,
				offsetX : 8,
				offsetY : 8
			});
		}
	});
	$(window).scroll(function() {
		// 当滚动到最底部以上50像素时， 加载新内容
		if ($(document).height() - $(this).scrollTop() - $(this).height() < 50) {
			$('#container').append($("#test").html());
			$('#container').BlocksIt({
				numOfCol : 5,
				offsetX : 8,
				offsetY : 8
			});
			$("img.lazy").lazyload();
			index++;
			findSingersByPage(index);
		}
	});

	// window resize
	var currentWidth = 1100;
	$(window).resize(function() {
		var winWidth = $(window).width();
		var conWidth;
		if (winWidth < 660) {
			conWidth = 440;
			col = 2
		} else if (winWidth < 880) {
			conWidth = 660;
			col = 3
		} else if (winWidth < 1100) {
			conWidth = 880;
			col = 4;
		} else {
			conWidth = 1100;
			col = 5;
		}

		if (conWidth != currentWidth) {
			currentWidth = conWidth;
			$('#container').width(conWidth);
			$('#container').BlocksIt({
				numOfCol : col,
				offsetX : 8,
				offsetY : 8
			});
		}
	});

	var nydiv = document.getElementById("returntoppp");
	var divTop = nydiv.offsetTop;
	// alert(divTop);

	function ret() {
		var docLength = document.body.scrollTop;
		// alert(docLength);
		nydiv.style.top = docLength + divTop + "px";
	}

	function returnTop() {
		document.body.scrollTop = 0 + "px";

	}

	window.onscroll = ret;

});

/**
 * 加载主页面歌手
 */
function addMainSinger() {
	$.post(path + "/main/addMainSinger.do", {}, function(result) {
		if (result.success) {
			var list = result.data;
			$(list).each(function() {
				var div = '<div class="grid"><div class="imgholder"><a href="'
						+ path
						+ '/main/tosinger.do?singer_id='
						+ this.singer_id
						+ '" style="cursor:hand;"><img class="lazy" src="../image/singer/'+ this.singer_head + '" data-original="../image/singer/'
						+ this.singer_head + '"width="100%" /></a></div></div>';
				$("#container").append(div);
				$("#container div:last").data("singer", this);
			});
		} else {
			alert(result.message);
		}
	});
}
